#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/11/17
# @Author  : 邓大大
# @Desc    : pandas 处理交易行情数据的基础用法

import pandas as pd

df = pd.read_csv(filepath_or_buffer='/Users/denghui/Desktop/data_quantitative_pro/51bitquant/1559978820000.csv')
pd.set_option('expand_frame_repr', False)  # 当列太多时不换行
pd.set_option('display.max_rows', 1000)  # 最多显示行数
# print(df)
# print(df.dtypes)
# print(df.shape)
# print(df.columns)
# print(df.head())
# print(df.tail())
# print(df.describe()) # 非常方便的函数，对每一列数据有直观的感受，只会对数字类型的列有效
# print(df[['open_time','close']]) # 同时读取多列
# df['mark'] = "111111"
# df['exchange'] = "Binance"
# nums = [i for i in range(0, 940, 1)]
# df['numbers'] = nums
# print(df['numbers'] * 10)
# df['total_trade'] = (df['close'] * df['volume'])
# df['open_time'] = pd.to_datetime(df['open_time'], unit='ms') + pd.Timedelta(hours=8)  # 默认是UTC 0时区的时间，格林威治的时间, 跟北京时间需要加8小时
# print(df[['open_time', 'close', 'volume', 'total_trade']])  # 筛选
# print(df.iloc[0]['open'])
# print(df.iloc[0:4] )
# print(df.iloc[1:3 , 1:3])
# print(df.iat[1,1])

# ====统计函数
print(df['close'].mean())
print(df[['close', 'open']].mean())
print(df[['close', 'open']].mean(axis=1))  # 求两列的均值，axis = 0 或者 1 要搞清楚
print(df['high'].max())  # 最大值
print(df['low'].min())  # 最小值
print(df['close'].std())  # 标准差
print(df['close'].count())  # 非空的数据的数量
print(df['close'].median())  # 中位数
print(df['close'].quantile(0.25))  # 25% 分位数